﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="PhuongDoAn.Admin.Film.Default" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script src="/Theme/Scripts/UtilFunc.js" type="text/javascript"></script>
    <script src="/Theme/Scripts/UtilString.js" type="text/javascript"></script>
    <style type="text/css">
        .icon-arrowin { background-image: url("/icons/arrow_in-png/ext.axd") !important; }
        .x-panel-body-default { border-top-width: 0 !important; border-width: 0 !important; }
        #pnCustomSearch { background-color: #D8E4F3 !important; }
        .wrap .x-grid-cell-inner { white-space: normal; }
    </style>
    <script type="text/javascript" language="javascript">

        var prepare = function (grid, toolbar, rowIndex, record) {
            // toolbar.items.get(0).setTooltip('Xem chi tiết');
            toolbar.items.get(0).setTooltip('Sửa');
            toolbar.items.get(1).setTooltip('Xác nhận xóa');
        };

        var showCustomSearch = function () {
            var collaped = App.pnCustomSearch.getCollapsed();
            if (collaped) {
                App.pnCustomSearch.expand();
                App.btnCustomSearch.setIconCls("icon-arrowin");
                //an cac not do di
                App.btnSearch.setVisible(false);
                App.btnClear.setVisible(false);
                App.txtKeyWord.setVisible(false);
            } else {
                App.pnCustomSearch.collapse();
                App.btnCustomSearch.setIconCls("icon-arrowout");
                //hien thi cac node do di
                App.btnSearch.setVisible(true);
                App.btnClear.setVisible(true);
                App.txtKeyWord.setVisible(true);
            }
        };
        var reLoadData = function () {
            applyFilter();
        }
        var applyFilter = function () {
            App.gpDocument.store.loadPage(1);
            App.gpDocument.store.reload();
        }

        var clearFilter = function () {
            App.txtKeyWord.setValue('');
            App.gpDocument.store.loadPage(1);
            App.gpDocument.store.reload();
        }
        var date = function (value, p, record) {

            if (value == null) return "";
            value = value.replace(" ", "T");
            var temp = value.split("T");
            var date = temp[0].split("-");
            var dateStr = date[2] + "/" + date[1] + "/" + date[0];
            return dateStr;
        }
        ////Ham su li 
        var commandHandler = function (cmd, record) {
            switch (cmd) {
                case "add":
                    var url = 'Film/Edit.aspx';
                    var title = 'Thêm mới film';
                    id = "Doc_Document_Edit";
                    window.top.newWindow(url, { id: id, title: title, height: 600, width: 1000, modal: true });
                    break;
                case "detail":
                    //vao so van ban
                    var url = 'Film/Detail.aspx?ItemID=' + record.data.MovieID;
                    var title = 'Xem chi tiết';
                    id = "Doc_Document_Detail";
                    window.top.addDefaultTab(id, url, title);
                    break;
                case "edit":
                    url = 'Film/Edit.aspx?ItemID=' + record.data.MovieID;
                    title = 'Sửa film';
                    id = "Film_Edit";
                    window.top.newWindow(url, { id: id, title: title, height: 450, width: 1000, modal: true });
                    break;
                case "delete":
                    Ext.Msg.confirm('Xác nhận xóa', '<span style="color:red;">Xác nhận xóa:</span><b> ' + record.data.MovieName + '</b>', function (btn) {
                        if (btn == "yes") {
                            App.direct.Delete(record.data.MovieID, {
                                success: function (result) {
                                    applyFilter();
                                },
                                eventMask: {
                                    showMask: true,
                                    minDelay: 500
                                }
                            });
                        }
                    });
                    break;
            }
        }
        //Su kien select
        var doubleClick = function (dataview, record, item, index, e) {
            // App.hdfID.setValue(record.data.ID);
            commandHandler("edit", record);
            //            var url = 'Film/Detail.aspx?ItemID=' + record.data.MovieID;
            //            title = 'Xem chi tiết';
            //            id = "Doc_Document_Detail";
            //            window.top.newWindow(url, { title: title, height: 600, width: 1000, modal: true });
        }

        var TypeChange = function (button, pressed) {
            if (pressed) {
                App.txtType.setValue(button.getText().replaceAll("..", ""));
            }
            else {
                if (App.txtType.getValue() == button.getText().replaceAll("..", ""))
                    App.txtType.setValue('');
            }
            applyFilter();
            //    PagingToolBar1.changePage(1);
        }

        var imageurlRender = function (value, p, record) {
            if (value == null) return '<img src="/Theme/Images/no-image.jpg" height="120px" />';
            if (value == '') {
                return '<img src="/Theme/Images/no-image.jpg"  height="120px" />';
            }

            return '<img src="/Files/Films/' + value + '" height="120px" />';
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <ext:ResourceManager ID="ResourceManager1" runat="server" ShowWarningOnAjaxFailure="true">
        <Listeners>
            <DocumentReady Handler="showCustomSearch();" />
        </Listeners>
    </ext:ResourceManager>
    <%--Store dung du lieu--%>
    <ext:Store ID="storeData" runat="server" PageSize="20">
        <Proxy>
            <ext:AjaxProxy Url="Handler/ListHandler.ashx">
                <ActionMethods Read="GET">
                </ActionMethods>
                <Reader>
                    <ext:JsonReader Root="Data" TotalProperty="TotalRecords">
                    </ext:JsonReader>
                </Reader>
            </ext:AjaxProxy>
        </Proxy>
        <AutoLoadParams>
            <ext:Parameter Name="start" Value="={0}" />
        </AutoLoadParams>
        <Model>
            <ext:Model ID="Model1" runat="server">
                <Fields>
                    <ext:ModelField Name="MovieID" />
                    <ext:ModelField Name="MovieName" />
                    <ext:ModelField Name="Year" />
                    <ext:ModelField Name="ImageUrl" />
                    <ext:ModelField Name="Status" />
                    <ext:ModelField Name="Runtime" />
                    <ext:ModelField Name="Director" />
                </Fields>
            </ext:Model>
        </Model>
        <Parameters>
            <ext:StoreParameter Name="limit" Mode="Raw" Value="#{cbPageSize}.getValue()" />
            <ext:StoreParameter Name="keyWord" Mode="Raw" Value="#{txtKeyWord}.getValue()" />
            <ext:StoreParameter Name="type" Mode="Raw" Value="#{txtType}.getValue()" />
            <ext:StoreParameter Name="collapse" Mode="Raw" Value="#{pnCustomSearch}.getCollapsed()" />
        </Parameters>
    </ext:Store>
    <%--View port--%>
    <ext:Viewport ID="vp" runat="server" Layout="BorderLayout">
        <Items>
            <ext:Panel ID="Panel1" runat="server" Border="false" Layout="FitLayout" Region="Center"
                Split="true">
                <Items>
                    <ext:Panel runat="server" ID="pnMain" Region="North" Layout="FitLayout" Border="false"
                        Collapsed="false">
                        <TopBar>
                            <ext:Toolbar ID="Toolbar1" runat="server">
                                <Items>
                                    <ext:Button ID="btnAdd" runat="server" Text="Thêm mới" Icon="Add">
                                        <Listeners>
                                            <Click Handler="commandHandler('add');" />
                                        </Listeners>
                                    </ext:Button>
                                    <ext:ToolbarFill />
                                    <ext:TextField ID="txtKeyWord" runat="server" MaxLength="255" EmptyText="Từ khóa">
                                    </ext:TextField>
                                    <ext:Button ID="btnSearch" runat="server" Icon="Zoom">
                                        <Listeners>
                                            <Click Handler="applyFilter();" />
                                        </Listeners>
                                    </ext:Button>
                                    <ext:Button ID="btnClear" runat="server" Icon="ArrowRefresh">
                                        <Listeners>
                                            <Click Handler="clearFilter();" />
                                        </Listeners>
                                    </ext:Button>
                                    <ext:Button ID="btnCustomSearch" runat="server" Icon="ArrowOut">
                                        <Listeners>
                                            <Click Handler="showCustomSearch();" />
                                        </Listeners>
                                    </ext:Button>
                                </Items>
                            </ext:Toolbar>
                        </TopBar>
                        <Items>
                            <ext:Panel runat="server" ID="pnLeft" Layout="BorderLayout" Border="false">
                                <Items>
                                    <ext:FormPanel Region="North" ID="pnCustomSearch" runat="server" Border="false" CollapseMode="Mini"
                                        ButtonAlign="Center" Height="50" TitleCollapse="false" HideCollapseTool="true"
                                        Collapsed="true">
                                        <Content>
                                            <ext:Button ID="Button1" Text="A.." runat="server" EnableToggle="true" ToggleGroup="toggleGroup">
                                                <Listeners>
                                                    <Toggle Fn="TypeChange" />
                                                </Listeners>
                                            </ext:Button>
                                            <ext:Button ID="Button2" Text="B.." runat="server" EnableToggle="true" ToggleGroup="toggleGroup">
                                                <Listeners>
                                                    <Toggle Fn="TypeChange" />
                                                </Listeners>
                                            </ext:Button>
                                            <ext:Button ID="Button3" Text="C.." runat="server" EnableToggle="true" ToggleGroup="toggleGroup">
                                                <Listeners>
                                                    <Toggle Fn="TypeChange" />
                                                </Listeners>
                                            </ext:Button>
                                            <ext:Button ID="Button4" Text="D.." runat="server" EnableToggle="true" ToggleGroup="toggleGroup">
                                                <Listeners>
                                                    <Toggle Fn="TypeChange" />
                                                </Listeners>
                                            </ext:Button>
                                            <ext:Button ID="Button5" Text="E.." runat="server" EnableToggle="true" ToggleGroup="toggleGroup">
                                                <Listeners>
                                                    <Toggle Fn="TypeChange" />
                                                </Listeners>
                                            </ext:Button>
                                            <ext:Button ID="Button6" Text="F.." runat="server" EnableToggle="true" ToggleGroup="toggleGroup">
                                                <Listeners>
                                                    <Toggle Fn="TypeChange" />
                                                </Listeners>
                                            </ext:Button>
                                            <ext:Button ID="Button7" Text="G.." runat="server" EnableToggle="true" ToggleGroup="toggleGroup">
                                                <Listeners>
                                                    <Toggle Fn="TypeChange" />
                                                </Listeners>
                                            </ext:Button>
                                            <ext:Button ID="Button8" Text="H.." runat="server" EnableToggle="true" ToggleGroup="toggleGroup">
                                                <Listeners>
                                                    <Toggle Fn="TypeChange" />
                                                </Listeners>
                                            </ext:Button>
                                            <ext:Button ID="Button9" Text="I.." runat="server" EnableToggle="true" ToggleGroup="toggleGroup">
                                                <Listeners>
                                                    <Toggle Fn="TypeChange" />
                                                </Listeners>
                                            </ext:Button>
                                            <ext:Button ID="Button10" Text="J.." runat="server" EnableToggle="true" ToggleGroup="toggleGroup">
                                                <Listeners>
                                                    <Toggle Fn="TypeChange" />
                                                </Listeners>
                                            </ext:Button>
                                            <ext:Button ID="Button11" Text="K.." runat="server" EnableToggle="true" ToggleGroup="toggleGroup">
                                                <Listeners>
                                                    <Toggle Fn="TypeChange" />
                                                </Listeners>
                                            </ext:Button>
                                            <ext:Button ID="Button12" Text="L.." runat="server" EnableToggle="true" ToggleGroup="toggleGroup">
                                                <Listeners>
                                                    <Toggle Fn="TypeChange" />
                                                </Listeners>
                                            </ext:Button>
                                            <ext:Button ID="Button13" Text="M.." runat="server" EnableToggle="true" ToggleGroup="toggleGroup">
                                                <Listeners>
                                                    <Toggle Fn="TypeChange" />
                                                </Listeners>
                                            </ext:Button>
                                            <ext:Button ID="Button14" Text="N.." runat="server" EnableToggle="true" ToggleGroup="toggleGroup">
                                                <Listeners>
                                                    <Toggle Fn="TypeChange" />
                                                </Listeners>
                                            </ext:Button>
                                            <ext:Button ID="Button15" Text="O.." runat="server" EnableToggle="true" ToggleGroup="toggleGroup">
                                                <Listeners>
                                                    <Toggle Fn="TypeChange" />
                                                </Listeners>
                                            </ext:Button>
                                            <ext:Button ID="Button16" Text="P.." runat="server" EnableToggle="true" ToggleGroup="toggleGroup">
                                                <Listeners>
                                                    <Toggle Fn="TypeChange" />
                                                </Listeners>
                                            </ext:Button>
                                            <ext:Button ID="Button17" Text="R.." runat="server" EnableToggle="true" ToggleGroup="toggleGroup">
                                                <Listeners>
                                                    <Toggle Fn="TypeChange" />
                                                </Listeners>
                                            </ext:Button>
                                            <ext:Button ID="Button18" Text="S.." runat="server" EnableToggle="true" ToggleGroup="toggleGroup">
                                                <Listeners>
                                                    <Toggle Fn="TypeChange" />
                                                </Listeners>
                                            </ext:Button>
                                            <ext:Button ID="Button19" Text="T.." runat="server" EnableToggle="true" ToggleGroup="toggleGroup">
                                                <Listeners>
                                                    <Toggle Fn="TypeChange" />
                                                </Listeners>
                                            </ext:Button>
                                            <ext:Button ID="Button20" Text="U.." runat="server" EnableToggle="true" ToggleGroup="toggleGroup">
                                                <Listeners>
                                                    <Toggle Fn="TypeChange" />
                                                </Listeners>
                                            </ext:Button>
                                            <ext:Button ID="Button21" Text="V.." runat="server" EnableToggle="true" ToggleGroup="toggleGroup">
                                                <Listeners>
                                                    <Toggle Fn="TypeChange" />
                                                </Listeners>
                                            </ext:Button>
                                            <ext:Button ID="Button22" Text="W.." runat="server" EnableToggle="true" ToggleGroup="toggleGroup">
                                                <Listeners>
                                                    <Toggle Fn="TypeChange" />
                                                </Listeners>
                                            </ext:Button>
                                            <ext:Button ID="Button23" Text="X.." runat="server" EnableToggle="true" ToggleGroup="toggleGroup">
                                                <Listeners>
                                                    <Toggle Fn="TypeChange" />
                                                </Listeners>
                                            </ext:Button>
                                            <ext:Button ID="Button24" Text="Y.." runat="server" EnableToggle="true" ToggleGroup="toggleGroup">
                                                <Listeners>
                                                    <Toggle Fn="TypeChange" />
                                                </Listeners>
                                            </ext:Button>
                                            <ext:Button ID="Button25" Text="Z.." runat="server" EnableToggle="true" ToggleGroup="toggleGroup">
                                                <Listeners>
                                                    <Toggle Fn="TypeChange" />
                                                </Listeners>
                                            </ext:Button>
                                            <ext:Button ID="Button26" Text="0.." runat="server" EnableToggle="true" ToggleGroup="toggleGroup">
                                                <Listeners>
                                                    <Toggle Fn="TypeChange" />
                                                </Listeners>
                                            </ext:Button>
                                            <ext:Button ID="Button27" Text="1.." runat="server" EnableToggle="true" ToggleGroup="toggleGroup">
                                                <Listeners>
                                                    <Toggle Fn="TypeChange" />
                                                </Listeners>
                                            </ext:Button>
                                            <ext:Button ID="Button28" Text="2.." runat="server" EnableToggle="true" ToggleGroup="toggleGroup">
                                                <Listeners>
                                                    <Toggle Fn="TypeChange" />
                                                </Listeners>
                                            </ext:Button>
                                            <ext:Button ID="Button29" Text="3.." runat="server" EnableToggle="true" ToggleGroup="toggleGroup">
                                                <Listeners>
                                                    <Toggle Fn="TypeChange" />
                                                </Listeners>
                                            </ext:Button>
                                            <ext:Button ID="Button30" Text="4.." runat="server" EnableToggle="true" ToggleGroup="toggleGroup">
                                                <Listeners>
                                                    <Toggle Fn="TypeChange" />
                                                </Listeners>
                                            </ext:Button>
                                            <ext:Button ID="Button31" Text="5.." runat="server" EnableToggle="true" ToggleGroup="toggleGroup">
                                                <Listeners>
                                                    <Toggle Fn="TypeChange" />
                                                </Listeners>
                                            </ext:Button>
                                            <ext:Button ID="Button32" Text="6.." runat="server" EnableToggle="true" ToggleGroup="toggleGroup">
                                                <Listeners>
                                                    <Toggle Fn="TypeChange" />
                                                </Listeners>
                                            </ext:Button>
                                            <ext:Button ID="Button33" Text="7.." runat="server" EnableToggle="true" ToggleGroup="toggleGroup">
                                                <Listeners>
                                                    <Toggle Fn="TypeChange" />
                                                </Listeners>
                                            </ext:Button>
                                            <ext:Button ID="Button34" Text="8.." runat="server" EnableToggle="true" ToggleGroup="toggleGroup">
                                                <Listeners>
                                                    <Toggle Fn="TypeChange" />
                                                </Listeners>
                                            </ext:Button>
                                            <ext:Button ID="Button35" Text="9.." runat="server" EnableToggle="true" ToggleGroup="toggleGroup">
                                                <Listeners>
                                                    <Toggle Fn="TypeChange" />
                                                </Listeners>
                                            </ext:Button>
                                            <ext:Hidden ID="txtType" runat="server" Text="">
                                            </ext:Hidden>
                                        </Content>
                                    </ext:FormPanel>
                                    <ext:Panel ID="Panel4" runat="server" Region="Center" Header="false" Border="false"
                                        Layout="FitLayout">
                                        <Items>
                                            <ext:GridPanel ID="gpDocument" runat="server" Frame="true" AutoExpandColumn="Title"
                                                Split="true" AutoEncode="true" StoreID="storeData" Border="false">
                                                <ColumnModel ID="ColumnModel1" runat="server">
                                                    <Columns>
                                                        <ext:RowNumbererColumn ID="RowNumbererColumn1" runat="server" Text="STT" Width="30"
                                                            Align="Center" Resizable="false" />
                                                        <ext:CommandColumn ID="CommandColumn1" runat="server" Align="Center" Resizable="false"
                                                            ColumnID="ColumnIDTool" Wrap="true" Width="80">
                                                            <Commands>
                                                                
                                                                <ext:GridCommand Icon="TableEdit" CommandName="edit" />
                                                                <ext:GridCommand Icon="Delete" CommandName="delete" />
                                                            </Commands>
                                                            <PrepareToolbar Fn="prepare" />
                                                            <Listeners>
                                                                <Command Handler="commandHandler(command,  record);" />
                                                            </Listeners>
                                                        </ext:CommandColumn>
                                                        <ext:Column ID="Column1" ColumnID="Code" DataIndex="ImageUrl" Width="120" Sortable="true"
                                                            Groupable="false" runat="server" Text="Ảnh">
                                                            <Renderer Fn="imageurlRender" />
                                                        </ext:Column>
                                                        <ext:Column ID="Coludfafmn2" DataIndex="MovieName" ColumnID="Title" runat="server"
                                                            TdCls="wrap" Flex="1" Groupable="false" Text="Tên film" />
                                                        <ext:Column ID="Column2" DataIndex="Director" ColumnID="Titdfdfle" runat="server"
                                                            TdCls="wrap" Width="200" Groupable="false" Text="Đạo diễn" />
                                                        <ext:Column ID="Column6" ColumnID="đfd" DataIndex="Status" Width="60" Sortable="true"
                                                            Groupable="false" runat="server" Text="Trạng thái" />
                                                    </Columns>
                                                </ColumnModel>
                                                <SelectionModel>
                                                    <ext:RowSelectionModel ID="RowSelectionModel1" runat="server">
                                                    </ext:RowSelectionModel>
                                                </SelectionModel>
                                                <BottomBar>
                                                    <ext:PagingToolbar AutoScroll="true" ID="PagingToolbar1" runat="server" PageSize="20"
                                                        EmptyMsg="Không có bản ghi nào để hiển thị">
                                                        <Items>
                                                            <ext:Label ID="lblPageSize" runat="server" Text="Số bản ghi trên trang" />
                                                            <ext:ToolbarSpacer ID="ToolbarSpacer1" runat="server" Width="10" />
                                                            <ext:ComboBox ID="cbPageSize" runat="server" Width="55" Editable="false">
                                                                <Items>
                                                                    <ext:ListItem Text="10" />
                                                                    <ext:ListItem Text="20" />
                                                                    <ext:ListItem Text="30" />
                                                                </Items>
                                                                <SelectedItems>
                                                                    <ext:ListItem Value="20" Text="20" />
                                                                </SelectedItems>
                                                                <Listeners>
                                                                    <Select Handler="#{gpDocument}.store.pageSize= parseInt(this.getValue());#{gpDocument}.store.loadPage(1); #{gpDocument}.store.reload();" />
                                                                </Listeners>
                                                            </ext:ComboBox>
                                                        </Items>
                                                    </ext:PagingToolbar>
                                                </BottomBar>
                                                <Listeners>
                                                    <ItemDblClick Fn="doubleClick" />
                                                </Listeners>
                                            </ext:GridPanel>
                                        </Items>
                                    </ext:Panel>
                                </Items>
                            </ext:Panel>
                        </Items>
                    </ext:Panel>
                </Items>
            </ext:Panel>
        </Items>
    </ext:Viewport>
    </form>
</body>
</html>
